import {
  Body,
  Controller,
  Get,
  Post,
  Put,
  Query,
  UseGuards,
} from '@nestjs/common';
import { MicrosoftBearerGuard } from 'src/auth/microsoft-bearer.guard';
import { UserService } from './user.service';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Post('getAllUsers')
  @UseGuards(MicrosoftBearerGuard)
  async getAll(
    @Body()
    filter: {
      selectedSort:
        | 'lastName:ASC'
        | 'lastName:DESC'
        | 'firstName:ASC'
        | 'firstName:DESC'
        | '';
      selectedCities: string[];
      selectedOrgs: string[];
      selectedPositions: string[];
    },
    @Query() query: { orgUUID: string | null },
  ) {
    return await this.userService.getAll(filter, query.orgUUID);
  }

  @Post('getFavorites')
  @UseGuards(MicrosoftBearerGuard)
  async getFavorites(
    @Body()
    body: {
      favorites: string[];
      filter: {
        selectedSort:
          | 'lastName:ASC'
          | 'lastName:DESC'
          | 'firstName:ASC'
          | 'firstName:DESC'
          | '';
        selectedCities: string[];
        selectedOrgs: string[];
        selectedPositions: string[];
      };
    },
  ) {
    return await this.userService.getFavorites(body);
  }

  @Put('setFavorite')
  @UseGuards(MicrosoftBearerGuard)
  async setFavorite(@Body() body: { userId: string; favoriteId: string }) {
    return await this.userService.setFavorite(body);
  }

  @Get('getUserById')
  @UseGuards(MicrosoftBearerGuard)
  async getUserById(@Query() query: { contactId: string }) {
    return await this.userService.getUserById(query.contactId);
  }

  @Get('getUserPhoto')
  @UseGuards(MicrosoftBearerGuard)
  getPhoto(@Query() query: { contactId: string }) {
    return this.userService.getPhoto(query.contactId);
  }
}
